package com.zmj.sy.mom.srv.aps.bean.vo.base;

import com.zmj.sy.mom.srv.aps.utils.MkBeanUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
public class BaseListResVo<T> extends BaseResVo {


    private List<T> data;


    public BaseListResVo(List<T> data) {
        this.data = data;
    }

    public BaseListResVo(Collection<T> data) {
//        this.data = data;
        if(this.data == null){
            this.data = new ArrayList<>();
        }
        this.data.addAll(data);
    }

    @SneakyThrows
    public static <T> BaseListResVo<T> of(List<?> shiftPage, Class<T> clazz) {
        List<T> l = shiftPage
                .stream()
                .map(e -> MkBeanUtils.copyProperties(e, clazz))
                .collect(Collectors.toList());
        return new BaseListResVo<>(l);
    }

    public static <T> BaseListResVo<T> empty() {
        return new BaseListResVo<>(new ArrayList<>());
    }
}
